package com.yanqu.road.server.manger;

import com.alibaba.fastjson.JSONObject;
import com.yanqu.road.entity.annualreport.AnnualReportData;
import com.yanqu.road.entity.enums.eAnnualReportItem;
import com.yanqu.road.logic.bussiness.platform.PlatformBussiness;
import com.yanqu.road.server.TempMgr;

import java.util.Map;

public class AnnualReportMgr extends TempMgr {
    private static Map<Long, AnnualReportData> annualReportDataMap;

    @Override
    public boolean init() throws Exception {
        return reload();
    }

    @Override
    public boolean reloadConfig() throws Exception {
        return true;
    }

    @Override
    public boolean reloadData() throws Exception {
        annualReportDataMap = PlatformBussiness.getAnnualReportDataMap();
        return true;
    }

    @Override
    public boolean stop() {
        return false;
    }

    public static AnnualReportData getAnnualReportData(long userId){
        return annualReportDataMap.get(userId);
    }

    public static JSONObject parseJson(AnnualReportData annualReportData){
        JSONObject dataObj = new JSONObject();
        dataObj.put("userId", annualReportData.getUserId());
        for(Map.Entry<Integer, String> dataEntry : annualReportData.getReportDataMap().entrySet()){
            int key = dataEntry.getKey();
            String value = dataEntry.getValue();
            eAnnualReportItem reportItem = eAnnualReportItem.forKey(key);
            if (null != reportItem) {
                dataObj.put(reportItem.getValue(), value);
            }
        }
        return dataObj;
    }
}
